# -*- coding:utf-8 -*-
import enum
import uuid
from datetime import datetime
from typing import Any, Dict, List, Optional, Sequence, Union

from pydantic import BaseModel


class Job(BaseModel):
    id: Union[int, str, uuid.UUID]
    name: Optional[str] = None
    func: Optional[str] = None
    # if python 3.9.x, can use `tuple` key word to replace `Sequence[Optional[str]]`,
    # else use `Sequence[Optional[str]]` to deal with the issue about tuple length error.
    args: Optional[Sequence[Optional[str]]] = None
    kwargs: Optional[Dict[str, Any]] = None
    executor: Optional[str] = None
    misfire_grace_time: Optional[str] = None
    coalesce: Optional[bool] = None
    max_instances: Optional[int] = None
    next_run_time: Optional[Union[str, datetime]] = None


class TriggerEnum(str, enum.Enum):
    date = "date"
    interval = "interval"
    cron = "cron"


class Rescheduler(BaseModel):
    id: Union[int, str, uuid.UUID]
    trigger: TriggerEnum
    trigger_args: Optional[Dict[str, Any]]


class BaseResponse(BaseModel):
    message: str
    status_code: Union[int, str]


class QueryResponse(BaseResponse):
    jobs: List[Job]


class OperateResponse(BaseResponse):
    type: str
